<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<table id="weixin_msg_dtb_table"></table>
<script type="text/javascript">
    var $=$||{};
    var $weixin_msg_dtb_table=$('#weixin_msg_dtb_table');
    var $rtypes={
    		link:'接收到链接消息',
    		image:'接收到图片消息',
    		voice:'接收到语音消息',
    		video:'接收到视频消息',
    		location:'地理位置消息',
    		event:'接收到事件消息',
    		datas:undefined,
    		getData:function(){
    			if(this.datas){
    				return this.datas;
    			}
    			var aa=[];
    			$.each(this,function(i,n){
    				if(typeof(n)=='string'){
    					aa.push({label:n,value:i});
    				}
    			});
    			return this.datas=aa;
    		}
    };
    var $events={
    		wu:'无',
    		subscribe:'用户订阅',
    		unsubscribe:'用户取消订阅',
    		LOCATION:'地理位置事件',
    		CLICK:'自定义菜单事件',
    		datas:undefined,
    		getData:function(){
    			if(this.datas){
    				return this.datas;
    			}
    			var aa=[];
    			$.each(this,function(i,n){
    				if(typeof(n)=='string'){
    					aa.push({label:n,value:i});
    				}
    			});
    			return this.datas=aa;
    		}
    };
    $weixin_msg_dtb_table.datagrid({
        url:'msgrole/list.json',
        saveUrl:'msgrole/api?method=add',
        editUrl:'msgrole/api?method=update',
        delUrl:'msgrole/api?method=del',
        columns: [[
            {field:'ck',checkbox:true},
            {
                field:'id',
                title:'分发id'
            },
            {
                field:'rtype',
                title:'收到消息',
                width:180,
                formatter:function(value){
                    return $rtypes[value];
                }/* ,
                editor:{
                	type:'combobox',
                	options:{
                		required: true,
                		valueField: 'value',
                        textField: 'label',
                        data:rtypes.getData()
                	}
                } */
            },
            {
                field:'prsid',
                title:'消息处理器',
                width:400,
                formatter:function(value,row){
                    return row.prsname;
                },
                editor:{
                    type: 'combogrid',
                    options: {
                        required: true,
                        idField:'id',
                        textField:'name',
                        url:'msgprs/list.json',
                        pagination:true,
                        columns:[[
                            {field:'ck',checkbox:true},
                            {field:'name',title:'名称'},
                            {field: 'retype', title: '返回类型',
                            	formatter:function(value){
                            		return msglist[value];
                            	}	
                            },
                            {field: 'msgId', title: '消息id'},
                            {field: 'plugin', title: '对应插件'}
                        ]]
                    }
                }
            },
            {
            	field:'event',
            	title:'事件类型',
            	width:180,
            	editor:{type:'combobox',options:{
            		required:true,
            		valueField: 'value',
                    textField: 'label',
                    data:$events.getData()
            		}
            	},
            	formatter:function(value){
                    if(value){
                    	return $events[value];
                    }
                }
            },
            {
            	field:'eventkey',
            	title:'事件key',
            	width:180,
            	editor:{type:'textbox',options:{required:true}}
            }
        ]],
        onBeforeEdit:function(rowIndex){
            var edititem=$weixin_msg_dtb_table.datagrid('options').edititem;
            edititem.push(rowIndex);
        },
        onDblClickRow:function(rowIndex){
            $weixin_msg_dtb_table.datagrid('beginEdit',rowIndex);
        },
        toolbar:[
                 {
                	 iconCls:'icon-add',
                     text:'添加事件消息',
                     handler:function(){
                         $weixin_msg_dtb_table.datagrid('addRow',{rtype:'event'});
                     }
                 },
            {
                iconCls:'icon-save',
                text:'接受改变',
                handler:function(){
                    $weixin_msg_dtb_table.datagrid('RecChange',{prsid:'prsname'});
                }
            },
            {
                iconCls:'icon-save',
                text:'保存',
                handler:function(){
                	$weixin_msg_dtb_table.datagrid('SaveData');
                }
            },
            {
                iconCls:'icon-cancel',
                text:'取消更改',
                handler:function(){
                	$weixin_msg_dtb_table.datagrid('CancelEdit');
                }
            },
            {
                iconCls:'icon-remove',
                text:'删除',
                handler:function(){
                	$weixin_msg_dtb_table.datagrid('DelRows');
                }
            }
        ]
    });
</script>
</body>
</html>